package com.aoyy.dao;

import java.util.List;
import java.util.ArrayList;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.aoyy.model.ProductType;
/**==========================================================================================
 * <code>ProductTypeDaoImpl</code> class for <code>ProductType</code> DAO
 * @author Administrator
 * @date 2017-07-13
 * ========================================================================================== */
@Repository("productTypeDao")
@Transactional
public class ProductTypeDaoImpl extends BaseDaoImpl<ProductType> implements IProductTypeDao {
  @Override
  @Transactional(propagation=Propagation.NOT_SUPPORTED, readOnly=true)
  public Boolean isUniqueProductType(ProductType productType, Integer operation) {
	String hql;
	List<Object> list = new ArrayList<Object>();
	if (operation == 0) {
	  hql = "from ProductType where name = ?";
	  list.add(productType.getName());
	} else {
	  hql = "from ProductType where name = ? and typeId != ?";
	  list.add(productType.getName());
	  list.add(productType.getTypeId());
	}
	if (uniqueResult(hql, list.toArray()) != null) {
      return false;  
	}
	return true;
  }
}
